類型名稱 位元組 值的範圍
int 4 -2,147,483,648 至 2,147,483,647
short 2 -32,768 至 32,767
long 4 -2,147,483,648 至 2,147,483,647
long long 8 -9,223,372,036,854,775,808 至 9,223,372,036,854,775,807
float 4 3.4E +/- 38 (7 位數)
double 8 1.7E +/- 308 (15 位數)
參考延伸閱讀:https://docs.microsoft.com/zh-tw/cpp/cpp/data-type-ranges?view=msvc-170
the difference of number of soldiers between Hashmat's army and his opponent's army
求兩隊數量相差的絕對值。
關於此題目的小提醒:
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int h,o;
while(cin>>h>>o){
cout<<abs(h-o)<<endl;
}
return 0;
}
算出 2隊最後的得分
用聯立方程式可以解出
y=(a-b)/2
x=a-y
再用if限縮可能的情況
#include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
int a,b,x,y;
cin>>a>>b;
if(a-b>=0&&(a+b)%2==0){
y=(a-b)/2;
x=a-y;
cout<<x<<" "<<y<<endl;
}else cout<<"impossible"<<endl;
}
}
#include<iostream>
#include <iomanip>
#include <cmath>
#include <math.h>
using namespace std;
int main() {
double p1, p2, p3, p4, p5, p6, p7, p8, x, y;
while (cin >> p1 >> p2 >> p3 >> p4 >> p5 >> p6 >> p7 >> p8) {
if (p1 == p7 && p2 == p8) { //確認兩條邊重疊的點
x = p3 + (p5 - p1); //有四點是一樣的點,擇一作距離就好
y = p4 + (p6 - p2);
}
else if (p1 == p5 && p2 == p6) {
x = p3 + (p7 - p1);
y = p4 + (p8 - p2);
}
else if (p3 == p5 && p4 == p6) {
x = p1 + (p7 - p3);
y = p2 + (p8 - p4);
}
else if (p3 == p7 && p4 == p8) {
x = p1 + (p5 - p3);
y = p2 + (p6 - p4);
}
cout << fixed << setprecision(3); //取後三位
cout<< x << " " << y << endl;
}
}